-- 灵感笔技能（强制弃牌版）
local skill = fk.CreateSkill {
  name = "#twin_swords_skill",
  tags = { Skill.Compulsory },
  attached_equip = "twin_swords",
}

Fk:loadTranslationTable{
  ["#twin_swords_skill"] = "灵感笔",
  ["#twin_swords-discard"] = "灵感笔：使用【杀】时必须弃置一张牌",
}

-- 1. 无限出杀机制
skill:addEffect("targetmod", {
  bypass_times = function(self, player, _, scope, card)
    if player:hasSkill(skill.name) and card and card.trueName == "slash" and scope == Player.HistoryPhase then
      return true
    end
  end,
})

-- 2. 强制弃牌机制（移除取消选项）
skill:addEffect(fk.CardUsing, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and 
           data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    -- 强制弃牌（cancelable设为false，无取消选项）
    local discard = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = skill.name,
      cancelable = false,  -- 关键：不可取消
      prompt = "#twin_swords-discard",
      pattern = ".",
      -- 新增：无牌时自动弃置装备（若有）
      allow_equip = true,
      force = true,
    })
    -- 处理无牌可弃情况（强制弃置装备）
    if #discard == 0 then
      discard = room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = skill.name,
        cancelable = false,
        prompt = "#twin_swords-discard (无手牌时弃装备)",
        pattern = ".",
        force = true,
      })
    end
    if #discard > 0 then
      event:setCostData(self, {discard = discard})
      return true
    end
    return false  -- 无牌可弃时取消出杀
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(event:getCostData(self).discard, skill.name, player, player)
  end,
})

return skill
